<%@ page language="java" import="java.util.List" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> 
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
 
<html> 
	<head>
		<title>Poster</title>
        <link href="form/main.css" rel="stylesheet" type="text/css">
	</head>
	<body>
    	<logic:notPresent name="groups" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
		<logic:notPresent name="topic_name" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
		<logic:notPresent name="posters" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
		<logic:present name="userid" scope="session">
			<logic:notPresent name="name" scope="request">
				<logic:redirect page="/illegal_access.jsp"></logic:redirect>
			</logic:notPresent>
			<logic:notPresent name="grade" scope="request">
				<logic:redirect page="/illegal_access.jsp"></logic:redirect>
			</logic:notPresent>
		</logic:present>
		<logic:notPresent name="page" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
    	<% 
			int current_offset=(Integer) session.getAttribute("page");
			int list_size=((List) session.getAttribute("posters")).size();
			int current_end=current_offset+10;
			pageContext.setAttribute("co", current_offset);
		 %>
		<div class="container">
			<div class="header">
				<html:img page="/yssz.jpg"/>
                <div id="login">
                    <html:link action="mainPre">main page</html:link>
                    <logic:present name="search" scope="session">
                        <html:link page="/form/search.jsp">back to search engine</html:link>
                    </logic:present>
				</div>
			</div>
            <div class="sidebar1">
                <ul class="nav">
                    <logic:iterate id="groupList" name="groups" scope="session">
                        <bean:define id="groupName" name="groupList" property="name"></bean:define>
                        <li><a href="/se3/mainPre.do?group=<%=groupName %>"><bean:write name="groupName"/></a></li>
                    </logic:iterate>
                </ul>
			</div>
            <div class="content">
                <h3><bean:write name="topic_name" scope="session"/></h3>
               <logic:iterate id="posterList" name="posters" scope="session" length="10" offset="co">
	                    <div class="floor">
                        <h5>
                            <bean:define id="poster_id" name="posterList" property="posterid"></bean:define>
                            <logic:equal name="posterList" property="is_doctor" value="1">Dr. </logic:equal>
                            <bean:write name="posterList" property="user_name"/><br>
                            <logic:present name="admin" scope="session">
                                <a href="/se3/deletePoster.do?posterid=<%=poster_id %>">delete</a>
                            </logic:present>
                            <logic:present name="userid" scope="session">
                            	<logic:notPresent name="ban" scope="session">
                                	<a href="/se3/form/report.jsp?posterid=<%=poster_id %>">report to administrator</a>
                                </logic:notPresent>
                            </logic:present>
                        </h5>
                        <p><bean:write name="posterList" property="content"/></p>
                        <p class="time"><bean:write name="posterList" property="create_time"/></p>
                    </div>
                </logic:iterate>
                <% 
                    boolean have=false;
                    if(current_offset!=0) {
                        out.write("<a href=\"/se3/firstPage.do?from=poster\">首页</a> ");
                        out.write("<a href=\"/se3/previewPage.do?from=poster\">上一页</a> ");
                        have=true;
                    }
                    if(current_end<list_size) {
                        out.write("<a href=\"/se3/nextPage.do?from=poster\">下一页</a> ");
                        out.write("<a href=\"/se3/lastPage.do?from=poster&size="+list_size+"\">末页</a>");
                    }
                 %>
                <logic:present name="userid" scope="session">
                    <logic:notPresent name="ban" scope="session">
                    	<p>
	                        <html:form action="/addPoster">
	                            content : <html:textarea property="content" cols="80" rows="6"/><html:errors property="content"/><br/>
	                            <html:submit/>
	                        </html:form>
                        </p>
                    </logic:notPresent>
                </logic:present>
			</div>
			<div class="sidebar2">
				<logic:present name="userid" scope="session">
					<h4><html:link action="personalInformation"><bean:write name="name" scope="request"/></html:link></h4>
					<h4><bean:write name="grade" scope="request"/></h4>
				</logic:present>
				<logic:notPresent name="userid" scope="session">
					<ul class="nav">
						<li><html:link page="/form/login.jsp">login</html:link></li>
						<li><html:link page="/form/register.jsp">register</html:link></li>
					</ul>
				</logic:notPresent>
			</div>
            <div class="footer">
				<p>copyright@yssz</p>
			</div>
		</div>
	</body>
</html>